"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.GiveHistoryDao = void 0;
const DbConfig_1 = require("../../src/config/DbConfig");
const DaoBase_1 = require("../../src/engine/dao/DaoBase");
const DateUtil_1 = require("../../src/engine/utils/DateUtil");
const Logger_1 = require("../../src/engine/utils/Logger");
const MysqlManager_1 = require("../../src/engine/utils/MysqlManager");
class GiveHistoryDao extends DaoBase_1.DaoBase {
    static insert_give_history(param) {
        return __awaiter(this, void 0, void 0, function* () {
            let sender = param["sender"];
            let reciver = param["reciver"];
            let type = param["type"];
            let num = param["num"];
            let time = param["time"];
            let client = yield MysqlManager_1.MysqlManager.instance.getDb(this.DB_NAME);
            let sql = 'INSERT INTO t_give_history(sender,reciver,type,num,time) VALUES(?,?,?,?,?) ;';
            let sqlParams = [sender, reciver, type, num, time];
            client.queryPromise(sql, sqlParams);
        });
    }
    static get_give_history(sender, reciver, cur_page, page_size) {
        return __awaiter(this, void 0, void 0, function* () {
            let client = yield MysqlManager_1.MysqlManager.instance.getDb(this.DB_NAME);
            let startIndex = (cur_page - 1) * page_size;
            let sql = "select * from t_give_history where sender=? and reciver=?  limit ?,?";
            let sqlParams = [sender, reciver, startIndex, page_size];
            let rows = yield client.queryPromise(sql, sqlParams);
            Logger_1.Logger.log("get_give_history==", sql, sqlParams);
            if (rows && rows.length) {
                return rows;
            }
            return [];
        });
    }
    static get_give_history_totalnum(sender, reciver) {
        return __awaiter(this, void 0, void 0, function* () {
            let sql = "select count(*) from t_give_history where sender=? and reciver=?";
            let sqlParams = [sender, reciver];
            let client = yield MysqlManager_1.MysqlManager.instance.getDb(this.DB_NAME);
            let rows = yield client.queryPromise(sql, sqlParams);
            Logger_1.Logger.log("get_give_history_totalnum==", rows);
            if (rows) {
                return rows[0]["count(*)"];
            }
            return 0;
        });
    }
    static clear(delete_time) {
        return __awaiter(this, void 0, void 0, function* () {
            let client = yield MysqlManager_1.MysqlManager.instance.getDb(this.DB_NAME);
            let sql = "delete from t_give_history where time < ?";
            let sqlParams = [DateUtil_1.default.formatDateStr3(delete_time)];
            yield client.queryPromise(sql, sqlParams);
        });
    }
}
exports.GiveHistoryDao = GiveHistoryDao;
GiveHistoryDao.DB_NAME = DbConfig_1.DbConfig.Db_Name.db_admin;
